﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Paint.Mesh.CApMeshPartsValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.Paint.Mesh;

internal class CApMeshPartsValidator : ITxValidator
{
  public ITxObject GetObject(string str)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (!string.IsNullOrEmpty(str))
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(str);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject2))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj) => this.IsValidObject(obj, out string _);

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = (string) null;
    int num;
    switch (obj)
    {
      case null:
        num = 0;
        break;
      case TxComponent _:
      case TxCompoundResource _:
      case TxCompoundPart _:
        num = 1;
        break;
      default:
        num = obj is TxDevice ? 1 : 0;
        break;
    }
    bool flag = num != 0;
    if (!flag)
      errorMessage = MeshResource.MESH_MSG_INVALID_TYPE;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObject(text), out errorMessage);
  }
}
